/**
 * 
 */
package io.gitee.falllee.dao.config;

import java.util.Map;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.util.StringUtils;

import io.gitee.falllee.dao.model.BaseDaoConfig;
import io.gitee.falllee.dao.model.DaoConst;
import io.gitee.falllee.dao.util.CommonUtils;
import io.gitee.falllee.dao.util.FilterPlus;

/**
 * @author batty
 *
 */
@ConfigurationProperties(prefix="spring.dao", ignoreInvalidFields = true)
@PropertySource(value = "classpath:dao/dao.properties", ignoreResourceNotFound = true)
@Configuration("defaultDaoConfig")
public class DefaultDaoConfig extends BaseDaoConfig {
	
	@Override
	public Object getCurrentUser() {
	    String empNo = this.getHeaderParamEmpNo();
	    if (!StringUtils.hasLength(empNo)) {
	        return null;
	    }
	    Map<String, String> headerParamsMap = getHeaderParamsMap();
        for (String emp : empNo.split(DaoConst.COMMA)) {
            String val = CommonUtils.getValueIgnoreCase(headerParamsMap, emp);
            if (StringUtils.hasLength(val)) {
                return val;
            }
        }
        return null;
	}

    @Override
    public Map<String, String> getHeaderParamsMap() {
        return CommonUtils.getHeaderParam();
    }

    @Override
    public FilterPlus addGlobalFilter(FilterPlus filterPlus) {
        return filterPlus;
    }
}
